set_source_files_properties(
    dynamic_add_int32_v80.cce
    dynamic_maximum_float16_v80.cce
    dynamic_maximum_float32_v80.cce
    dynamic_maximum_int32_v80.cce
    dynamic_minimum_float16_v80.cce
    dynamic_minimum_float32_v80.cce
    dynamic_minimum_int32_v80.cce
    dynamic_mul_int32_v80.cce
    add_Ascend910_int8_210000000.cce
    add_Ascend910_int8_210010000.cce
    add_Ascend910_int8_223000000.cce
    add_Ascend910_int8_232000000.cce
    mul_Ascend910_int8_210000000.cce
    mul_Ascend910_int8_210010000.cce
    mul_Ascend910_int8_223000000.cce
    mul_Ascend910_int8_232000000.cce
    add_Ascend910_float16_210000000.cce
    add_Ascend910_float16_210010000.cce
    add_Ascend910_float16_223000000.cce
    add_Ascend910_float16_223010000.cce
    add_Ascend910_float16_232000000.cce
    add_Ascend910_float16_232010000.cce
    mul_Ascend910_float16_210000000.cce
    mul_Ascend910_float16_210010000.cce
    mul_Ascend910_float16_223000000.cce
    mul_Ascend910_float16_223010000.cce
    mul_Ascend910_float16_232000000.cce
    mul_Ascend910_float16_232010000.cce
    mul_Ascend910_float32_210000000.cce
    mul_Ascend910_float32_210010000.cce
    mul_Ascend910_float32_223000000.cce
    mul_Ascend910_float32_223010000.cce
    mul_Ascend910_float32_232000000.cce
    mul_Ascend910_float32_232010000.cce
    maximum_Ascend910_int8_210000000.cce
    maximum_Ascend910_int8_210010000.cce
    maximum_Ascend910_int8_223000000.cce
    maximum_Ascend910_int8_232000000.cce
    minimum_Ascend910_int8_210000000.cce
    minimum_Ascend910_int8_210010000.cce
    minimum_Ascend910_int8_223000000.cce
    minimum_Ascend910_int8_232000000.cce
    add_Ascend910_int64_210000000.cce
    add_Ascend910_int64_210010000.cce
    add_Ascend910_int64_2147483647.cce
    max_Ascend910_int64_210000000.cce
    max_Ascend910_int64_210010000.cce
    max_Ascend910_int64_2147483647.cce
    min_Ascend910_int64_210000000.cce
    min_Ascend910_int64_210010000.cce
    min_Ascend910_int64_2147483647.cce
    mul_Ascend910_int64_210000000.cce
    mul_Ascend910_int64_210010000.cce
    mul_Ascend910_int64_2147483647.cce
    MemSet_dynamic_AtomicAddrClean_1_ascend910.cce
    te_gatherv2_187b0f20dcf51283c20135753f6879d71370acd742114d5cb4847c86e660cd3c_1.cce
    te_gatherv2_08c676dd0564eaf646f0054fc0fb4adc559d7dca0155d698d2b788ce8a3a6a39_1.cce
    te_unsortedsegmentsum_da0a5264250330a6c92ab5b622124e7d75359168a46ae6eab47256ad57367ba9_1.cce
    te_unsortedsegmentsum_72b2c8c4c1584aa29ce28fc90a2f137f8e986479aa7adc062001be857271aea5_1.cce PROPERTIES LANGUAGE CXX
)

set_source_files_properties(te_gatherv2_187b0f20dcf51283c20135753f6879d71370acd742114d5cb4847c86e660cd3c_1.cce
    te_unsortedsegmentsum_da0a5264250330a6c92ab5b622124e7d75359168a46ae6eab47256ad57367ba9_1.cce
    PROPERTIES
    COMPILE_FLAGS
    "-mllvm -cce-aicore-function-stack-size=16000 \
    -mllvm -cce-aicore-record-overflow=false \
    -mllvm --cce-aicore-jump-expand=true"
)

add_library(hccl_reduce_op_ascend910_obj
    OBJECT dynamic_add_int32_v80.cce
           dynamic_maximum_float16_v80.cce
           dynamic_maximum_float32_v80.cce
           dynamic_maximum_int32_v80.cce
           dynamic_minimum_float16_v80.cce
           dynamic_minimum_float32_v80.cce
           dynamic_minimum_int32_v80.cce
           dynamic_mul_int32_v80.cce
           add_Ascend910_int8_210000000.cce
           add_Ascend910_int8_210010000.cce
           add_Ascend910_int8_223000000.cce
           add_Ascend910_int8_232000000.cce
           mul_Ascend910_int8_210000000.cce
           mul_Ascend910_int8_210010000.cce
           mul_Ascend910_int8_223000000.cce
           mul_Ascend910_int8_232000000.cce
           add_Ascend910_float16_210000000.cce
           add_Ascend910_float16_210010000.cce
           add_Ascend910_float16_223000000.cce
           add_Ascend910_float16_223010000.cce
           add_Ascend910_float16_232000000.cce
           add_Ascend910_float16_232010000.cce
           mul_Ascend910_float16_210000000.cce
           mul_Ascend910_float16_210010000.cce
           mul_Ascend910_float16_223000000.cce
           mul_Ascend910_float16_223010000.cce
           mul_Ascend910_float16_232000000.cce
           mul_Ascend910_float16_232010000.cce
           mul_Ascend910_float32_210000000.cce
           mul_Ascend910_float32_210010000.cce
           mul_Ascend910_float32_223000000.cce
           mul_Ascend910_float32_223010000.cce
           mul_Ascend910_float32_232000000.cce
           mul_Ascend910_float32_232010000.cce
           maximum_Ascend910_int8_210000000.cce
           maximum_Ascend910_int8_210010000.cce
           maximum_Ascend910_int8_223000000.cce
           maximum_Ascend910_int8_232000000.cce
           minimum_Ascend910_int8_210000000.cce
           minimum_Ascend910_int8_210010000.cce
           minimum_Ascend910_int8_223000000.cce
           minimum_Ascend910_int8_232000000.cce
           add_Ascend910_int64_210000000.cce
           add_Ascend910_int64_210010000.cce
           add_Ascend910_int64_2147483647.cce
           max_Ascend910_int64_210000000.cce
           max_Ascend910_int64_210010000.cce
           max_Ascend910_int64_2147483647.cce
           min_Ascend910_int64_210000000.cce
           min_Ascend910_int64_210010000.cce
           min_Ascend910_int64_2147483647.cce
           mul_Ascend910_int64_210000000.cce
           mul_Ascend910_int64_210010000.cce
           mul_Ascend910_int64_2147483647.cce
           MemSet_dynamic_AtomicAddrClean_1_ascend910.cce
           te_gatherv2_187b0f20dcf51283c20135753f6879d71370acd742114d5cb4847c86e660cd3c_1.cce
           te_gatherv2_08c676dd0564eaf646f0054fc0fb4adc559d7dca0155d698d2b788ce8a3a6a39_1.cce
           te_unsortedsegmentsum_da0a5264250330a6c92ab5b622124e7d75359168a46ae6eab47256ad57367ba9_1.cce
           te_unsortedsegmentsum_72b2c8c4c1584aa29ce28fc90a2f137f8e986479aa7adc062001be857271aea5_1.cce
)

target_compile_options(hccl_reduce_op_ascend910_obj PRIVATE
    -c
    -O2
    --cce-aicore-arch=dav-c100
    --cce-aicore-only
    -Wl,z,now
    -fPIE -pie
    -z now
    -fstack-protector-all
    -mllvm -cce-aicore-mask-opt=false
)

get_filename_component(CCE_DIR "${CMAKE_LINKER}" PATH)

#string(REPLACE "," " " hccl_reduce_op_ascend910_obj "$<TARGET_OBJECTS:hccl_reduce_op_ascend910_obj>")

add_custom_target(hccl_reduce_op_ascend910
    COMMAND ${CCE_DIR}/ld.lld -m aicorelinux -Ttext 0 $<TARGET_OBJECTS:hccl_reduce_op_ascend910_obj> -o ${CMAKE_CURRENT_BINARY_DIR}/hccl_reduce_op_ascend910.o
    WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
    COMMAND_EXPAND_LISTS
)
add_dependencies(hccl_reduce_op_ascend910 hccl_reduce_op_ascend910_obj)

install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hccl_reduce_op_ascend910.o OPTIONAL
    DESTINATION ${INSTALL_LIBRARY_DIR}
)